<?php
class DeptModel extends CommonModel {
    public $dept_id;
    public function __construct() {
        parent::__construct($name);
        if(!isset($this->dept_id)){
            $this->dept_id = session('dept_id');
        }
    }
    //获取下属部门ID
    public function get_child_ids(){
          $rs = $this->field('id,pid,children')->where("pid in ('$this->dept_id')" ) -> order('sort asc') -> select();
          $list[] = $this->dept_id;
          foreach($rs as $val){
              if($val['children']>0){
                  $list[] = $val['id'];
                  $this->dept_id = $val['id'];
                  $child_rs = $this->get_child_ids();
                  $list = array_merge($list,$child_rs);
              }else{
                  $list[] = $val['id'];
              }
          }
	  return $list;
    }
	
    public function get_pid(){//获取上级部门ID
        return $this -> where("id=$this->dept_id") -> order('sort asc') -> getField('pid');
    }
    
    }	
?>